{% load static %}
{% load utils %}
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <title>简历管理</title>
    <link rel="stylesheet" href="{% static '/public/css/ui.css' %}">
    <link rel="stylesheet" href="{% static '/public/admin/css/layout.css' %}">
    <script src="{% static '/public/js/jquery.js' %}"></script>
    <script src="{% static '/public/js/ui.js' %}"></script>
</head>

<body>
    <div class="position">当前位置：栏目管理 > <a href="/manager/resume/index/">简历管理</a></div>
    <div class="border">
        <!---->
        <div class="navbar">
            <div class="lefter">
                <a href="/manager/resume/add" class="ui-btn ui-btn-info ui-mr-sm">添加内容</a>
                <a href="javascript:;" class="ui-btn ui-btn-info ui-dropdown-show ui-mr-sm"
                    data-target="#dropdown-1">批量操作</a>
                <div class="ui-dropdown" id="dropdown-1">
                    <a href="javascript:;" class="ui-dropdown-item btach" type="1">设为已审</a>
                    <a href="javascript:;" class="ui-dropdown-item btach" type="2">设为未审</a>
                    <div class="ui-dropdown-line"></div>
                    <a href="javascript:;" class="ui-dropdown-item btach" type="3">批量删除</a>
                </div>
                <span class="ui-btn-group ui-btn-group-yellow ui-btn-group-bg">
                    <a class="ui-btn-group-item active" href="/manager/resume/index/?type=0">全部</a>
                    <a class="ui-btn-group-item" href="/manager/resume/index/?type=1">启用</a>
                    <a class="ui-btn-group-item" href="/manager/resume/index/?type=2">锁定</a>
                </span>
            </div>
        </div>
        <form method="post" class="ui-form">
            <div class="ui-table-wrap">
                <table class="ui-table ui-table-border ui-table-hover ui-table-striped ui-mt-20 ui-mb">
                    <thead class="ui-thead-gray">
                        <tr>
                            <th width="30" height="30"><label class="ui-checkbox tips" data-align="right-top"
                                    data-title="全选/取消"><input type="checkbox" class="checkall" value=""><i></i></label>
                            </th>
                            <th width="80">排序</th>
                            <th>申请职位</th>
                            <th>姓名</th>
                            <th width="120">发布日期</th>
                            <th width="130">发布IP</th>
                            <th width="50">状态</th>
                            <th width="150">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% if page_obj %}
                            {% for item in page_obj%}
                                <tr>
                                    <td><label class="ui-checkbox"><input type="checkbox" name="id" value="66"><i></i></label>
                                    </td>
                                    <td><input type="hidden" name="mid[]" value="66"><input type="text" name="ordnum[]"
                                            class="ui-form-ip" id="ordnum_66" value="0" data-rule="required;int;"></td>
                                    <td>{{item.my_title}}</td>
                                    <td>{{item.my_truename}}</td>
                                    <td>{{item.create_time}}</td>
                                    <td>{{item.my_ip}}</td>
                                    <td><label class="ui-switch ui-switch-info"><input type="checkbox" {% if item.islock == 1 %} checked{% endif %}
                                                data-url="/manager/resume/switchs/?id={{item.id}}"><span
                                                class="ui-switch-checkbox ui-switch-text"></span></label></td>
                                    <td><a href="/manager/resume/edit/?id={{item.id}}"><span class="ui-icon-edit"></span>
                                            编辑</a>　<a href="javascript:;" class="del"
                                            data-url="/manager/resume/delete/?id={{item.id}}"><span class="ui-icon-delete"></span>
                                            删除</a></td>
                                </tr>
                            {% endfor %}
                        {% endif %}
                    </tbody>
                </table>
            </div>
            {% csrf_token %}
        </form>
    </div>
    <script>
        const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
        $(function()
        {
            $('.ui-switch input[type=checkbox]').on('click',function()
            {
                var url=$(this).attr("data-url");
                var result=($(this).is(':checked'))?1:0;
                $.ajax(
                {
                    url:url,
                    type:"post",
                    dataType:'json',
                    data:"state="+result,
                    headers: {'X-CSRFToken': csrftoken},
                    mode: 'same-origin',
                    error:function(e){alert(e.responseText);},
                    success:function(d)
                    {
                        if(d.state=='success')
                        {
                            wmcms.success(d.msg);
                        }
                        else
                        {
                            wmcms.error(d.msg);
                        }
                    }
                });
            });
            
            $(".btach").click(function()
            {
                var type=$(this).attr("type");
                var data=[];
                $(".ui-form").find("input[type=checkbox]:checked").each(function()
                {
                    if($(this).attr("class")!='checkall' && !$(this).closest("label").hasClass("ui-switch"))
                    {
                        data.push($(this).val());
                    }
                });
                if(data.length==0)
                {
                    wmcms.error('至少选择一条内容');
                }
                else
                {
                    $.ajax(
                    {
                        type:'post',
                        cache:false,
                        dataType:'json',
                        url:'/admin/formdata/btach/fid/1.html',
                        data:'token=2aec52571a4ae6a5382e1a9c90fbd822&id='+data.join(",")+'&type='+type,
                        error:function(e){alert(e.responseText);},
                        success:function(d)
                        {
                            if(d.state=='success')
                            {
                                wmcms.success(d.msg);
                                setTimeout(function(){location.href='/admin/formdata/index/fid/1.html';},1500);
                            }
                            else
                            {
                                wmcms.error(d.msg);
                            }
                        }
                    });
                }
            });
            
            $(".del").click(function()
            {
                var url=$(this).attr("data-url");
                $.dialog(
                {
                    'title':"操作提示",
                    'text':"确定要删除？不可恢复！",
                    'oktheme':'ui-btn-info',
                    'ok':function(e)
                    {
                        $.ajax(
                        {
                            url:url,
                            type:'post',
                            dataType:'json',
                            data:'token=2aec52571a4ae6a5382e1a9c90fbd822',
                            error:function(e){alert(e.responseText);},
                            success:function(d)
                            {
                                e.close();
                                if(d.state=='success')
                                {
                                    wmcms.success(d.msg);
                                    setTimeout(function(){location.href='/admin/formdata/index/fid/1.html';},1000);
                                }
                                else
                                {
                                    wmcms.error(d.msg);
                                }
                            }
                        });
                    }
                });
            });
            
            $(".ui-form").form(
            {
                type:2,
                result:function(form)
                {
                    $.ajax(
                    {
                        type:'post',
                        cache:false,
                        dataType:'json',
                        url:'/admin/formdata/order/fid/1.html',
                        data:$(form).serialize(),
                        error:function(e){alert(e.responseText);},
                        success:function(d)
                        {
                            if(d.state=='success')
                            {
                                wmcms.success(d.msg);
                                setTimeout(function(){location.href='/admin/formdata/index/fid/1.html';},1500);
                            }
                            else
                            {
                                wmcms.error(d.msg);
                            }
                        }
                    });
                }
            });
        })
    </script>
</body>

</html>